import React, {Component} from 'react';
import PropTypes from 'prop-types'
import './top.scss'

//todoList头部输入框
class Top extends Component {
    static propTypes = {
        addItem: PropTypes.func.isRequired
    }
    onKeyDown = (e) => {
        const {keyCode, target} = e
        if (keyCode !== 13) return
        if (target.value.trim() === '') {
            alert('内容不能为空')
            return;
        }
        this.props.addItem(target.value)
        target.value = ''

    }

    render() {
        return (
            <div className="top-body">
                <input onKeyDown={this.onKeyDown} placeholder="请输入内容后按回车"/>
            </div>
        );
    }
}

export default Top;